FROM golang:1.13-alpine3.11 as builder
VOLUME /tmp

# Allows you to add additional packages via build-arg
ARG ADDITIONAL_PACKAGE
ARG CGO_ENABLED=0
ARG GO111MODULE="on"
ARG GOPROXY="https://goproxy.io,direct"
ARG GOFLAGS=""
ENV CGO_ENABLED=0
RUN mkdir -p /go/src
COPY go.mod /go/src
WORKDIR /go/src
RUN CGO_ENABLED=${CGO_ENABLED} GOOS=linux go mod download

COPY . /go/src/


RUN CGO_ENABLED=${CGO_ENABLED} GOOS=linux go build --ldflags "-s -w" -a -installsuffix cgo -o main main.go

FROM alpine:latest
LABEL MAINTAINER="awol2005ex@163.com"
RUN mkdir -p /go/src/
WORKDIR /go/src/
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates && addgroup -S app && adduser -S -g app app


COPY --from=builder /go/src/main ./
RUN chown app /go/src/main

RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone

RUN chmod +x main
USER app
EXPOSE 8080
ENTRYPOINT  ./main